<template>
	<view>
		<view class="logo">
			<view class="img">
				<image src="https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/zaizai-login/forget.png" mode="">
				</image>
			</view>
		</view>
		<view class="form re">
			<view class="username">
				<view class="get-code" :style="{ color: getCodeBtnColor }" @click.stop="getCode()">{{ getCodeText }}
				</view>
				<input placeholder="请输入手机号" v-model="phoneNumber" placeholder-style="color: rgba(255,255,255,0.8);" />
			</view>
			<view class="code"><input placeholder="请输入验证码" v-model="code"
					placeholder-style="color: rgba(255,255,255,0.8);" /></view>
			<view class="password"><input placeholder="请输入密码" v-model="passwd" password="true"
					placeholder-style="color: rgba(255,255,255,0.8);" /></view>

			<view class="password"><input placeholder="请输入新密码" v-model="newpasswd" password="true"
					placeholder-style="color: rgba(255,255,255,0.8);" /></view>
			<view class="btn" @tap="doReset">重置密码</view>


		</view>
	</view>
</template>

<script>
	import {
		message
	} from '../../../minixs/message.js';
	export default {
		data() {
			return {
				phoneNumber: '',
				code: '',
				passwd: '',
				getCodeText: '获取验证码',
				getCodeBtnColor: '#ffffff',
				getCodeisWaiting: false,
				newpasswd: '',
				content: "修改密码",
				type: 0
			};
		},
		mixins: [message],
		onLoad() {},
		methods: {
			Timer() {},

			isSimplePwd(s) {
				if (s.length < 6) {
					return 0;
				}
				var ls = 0;
				if (s.match(/([a-z])+/)) {
					ls++;
				}
				if (s.match(/([0-9])+/)) {
					ls++;
				}
				if (s.match(/([A-Z])+/)) {
					ls++;
				}

				return ls;
			},


			getCode() {
// console.log(this);
				if (this.getCodeisWaiting) {
					return;
				}
				if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber)) {
					uni.showToast({
						title: '请填写正确手机号码',
						icon: 'none'
					});
					return false;
				}
				this.getCodeText = '发送中...';
				this.getCodeisWaiting = true;
				this.getCodeBtnColor = 'rgba(255,255,255,0.5)';
				//示例用定时器模拟请求效果

				this.sendMessage()


				this.setTimer();
				//示例用定时器模拟请求效果

			},
			setTimer() {
				let holdTime = 60;
				this.getCodeText = '重新获取(60)';
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = '#ffffff';
						this.getCodeText = '获取验证码';
						clearInterval(this.Timer);
						return;
					}
					this.getCodeText = '重新获取(' + holdTime + ')';
					holdTime--;
				}, 1000);
			},
			doReset() {
				uni.hideKeyboard();
				//模板示例部分验证规则
				if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber)) {
					uni.showToast({
						title: '请填写正确手机号码',
						icon: 'none'
					});
					return false;
				}
				if (this.isSimplePwd(this.passwd) < 2) {
					uni.showToast({
						title: '密码必须包含数字、小写字母',
						icon: 'none'
					});
					return false;
				}

				if (this.newpasswd != this.passwd) {
					uni.showToast({
						title: '两次密码不一样',
						icon: 'none'
					});
					return false;
				}



		
				this.acceptTo()

			},
		}
	};
</script>

<style lang="scss">
	page {
		background: linear-gradient(to bottom, #f06c7a 0%, #f06c7a 100%);
		height: 100%;
	}

	.icon {
		color: #ffffff;
	}

	.logo {
		width: 100%;
		height: 45vw;
		display: flex;
		justify-content: center;
		align-items: center;

		.img {
			width: 25%;
			height: 25vw;
			background-color: #fff;
			border-radius: 100%;

			image {
				width: 100%;
				height: 100%;

				border-radius: 100%;
			}
		}
	}

	.form {
		width: 86%;
		padding: 0 7%;
		font-size: 30upx;

		.username,
		.password,
		.code {
			width: calc(100% - 90upx);
			height: 90upx;
			display: flex;
			align-items: center;
			border-radius: 45upx;
			background-color: rgba($color: #ffffff, $alpha: 0.1);
			padding: 0 45upx;
			margin-bottom: 26upx;

			input {
				width: 100%;
				height: 50upx;
				color: rgba($color: #ffffff, $alpha: 0.8);
				font-weight: 200;
			}
		}

		.btn {
			color: #f06c7a;
			width: 100%;
			height: 90upx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 45upx;
			background-color: #fff;
			font-size: 40upx;
		}
	}

	.re {
		.username {
			position: relative;

			.get-code {
				position: absolute;
				height: 90upx;
				display: flex;
				align-items: center;
				justify-content: center;
				right: 0;
				padding: 0 40upx;
				z-index: 3;

				&:after {
					content: ' ';
					width: 1upx;
					height: 50upx;
					background-color: #fff;
					position: absolute;
					z-index: 3;
					margin-right: 100%;
					left: 0;
					top: 20upx;
				}
			}
		}

		.res {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100upx;
			color: rgba($color: #ffffff, $alpha: 0.8);
		}
	}
</style>

